package com.manolovn.trianglify.util;

/**
 * Utility methods
 */
public class ClassUtil {
    private static final String TAG = ClassUtil.class.getSimpleName();
    /**
     * get class name by passing name
     *
     * @param className the name of class
     * @param classOfT specifies class sub type
     *
     * @return type specific object
     */
    public static <T> T getClassByName(String className, Class<T> classOfT) {
        try {
            Class<?> clazz = Class.forName(className);
            Object instance = clazz.newInstance();
            if (classOfT.isInstance(instance)) {
                return classOfT.cast(instance);
            }
        } catch (Exception e) {
            LogUtil.error(TAG, e.getMessage());
        }
        return null;
    }
}
